<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>DemoPortal</title>
    <meta charset="utf-8">
    <link href="${ctx}/static/kendoui/styles/kendo.common-material.min.css" rel="stylesheet">
    <link href="${ctx}/static/kendoui/styles/kendo.material.min.css" rel="stylesheet">
    <script src="${ctx}/static/jquery/js/jquery.min.js"></script>
    <script src="${ctx}/static/kendoui/js/kendo.web.min.js"></script>
</head>
<body>
<div id="example">
    <div class="demo-section k-content wide">
        <div>
            <h4>Add or update a record</h4>
            <div data-role="grid"
                 date-scrollable="true"
                 data-editable="true"
                 data-toolbar="['create', 'save']"
                 data-columns="[
                                 { 'field': 'id', 'width': 160 },
                                 { 'field': 'dictName', 'width': 270 },
                                 { 'field': 'remark' },
                              ]"
                 data-bind="source: dicts,
                            visible: isVisible,
                            events: {
                              save: onSave
                            }"
                 style="height: 600px"></div>
        </div>
        <div style="padding-top: 1em;">
            <h4>Console</h4>
            <div class="console"></div>
        </div>
    </div>
    <div class="box wide">
        <div class="box-col">
            <h4>Configuration</h4>
            <div>
                <label><input type="checkbox" data-bind="checked: isVisible">Visible</label>
            </div>
        </div>
        <div class="box-col">
            <h4>Information</h4>
            Kendo UI Grid supports the
        </div>
    </div>
    <script>
        var viewModel = kendo.observable({
            isVisible: true,
            onSave: function (e) {
                kendoConsole.log("event :: save(" + kendo.stringify(e.values, null, 4) + ")");
            },
            dicts: new kendo.data.DataSource({
                schema: {
                    total: "total",
                    data: "data",
                    groups: "data",
                    aggregates: "aggregates",
                    type: "json",
                    errors: "errors",
                    model: {
                        id: "id",
                        fields: {
                            dictName: {type: "string"},
                            remark: {type: "string"}
                        }
                    }
                },
                batch: true,
                transport: {
                    read: {
                        url: "/dict/list",
                        dataType: "json",
                    },
                    update: {
                        url: "/dict/update",
                        dataType: "json"
                    },
                    create: {
                        url: "/dict/create",
                        dataType: "json"
                    },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return {models: kendo.stringify(options.models)};
                        }
                    }
                }
            })
        });
        kendo.bind($("#example"), viewModel);
    </script>
</div>


</body>
</html>
